home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / tpstuff1.arc / WC.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1985-10-25  |  2.1 KB  |  79 lines

  1.  
  2.  program wc;
  3. {$I arglist.pin}
  4.     const
  5.        blank = ' ';
  6.        tab = ^I;
  7.        newline = ^J;
  8.        cr = ^M;
  9.        teof = ^Z;
  10.  
  11.     var
  12.        infile : file;
  13.        filename : string[20];
  14.        inbuf : array[1..512] of char;
  15.        words,lines,chars : REAL;
  16.        iptr : integer;
  17.        ch : char;
  18.        inword : boolean;
  19.  
  20.     begin
  21.        words := 0;
  22.        lines := 0;
  23.        chars := 0;
  24.        inword := false;
  25.        if argc <> 1 then begin
  26.        write('Input File Name To Use ');
  27.        readln(filename);
  28.        assign(infile,filename);
  29.        end
  30.        else assign(infile,argv(1));
  31.        reset(infile);
  32.        repeat
  33.        {$I-}
  34.           blockread(infile,inbuf,4);
  35.           {$I+}
  36.           if ioresult <> 0 then begin
  37.              clrscr;
  38.                 gotoxy(30,4);
  39.                 writeln ('In this file there were...');
  40.                 writeln;
  41.                 writeln(chars:6:0,'   Characters  ');
  42.                 writeln;
  43.                 writeln (words:6:0,'     Words  ');
  44.                 writeln;
  45.                 writeln (lines:6:0,'     Lines  ');
  46.                 halt;
  47.                 end;
  48.           iptr := 1;
  49.           while iptr <= 512 do begin
  50.              ch := inbuf[iptr];
  51.              chars := chars+1;
  52.              iptr := iptr+1;
  53.              if ch=teof then begin
  54.               clrscr;
  55.                 gotoxy(30,4);
  56.                 writeln ('In this file there were...');
  57.                 writeln;
  58.                 writeln(chars:6:0,'   Characters  ');
  59.                 writeln;
  60.                 writeln (words:6:0,'     Words  ');
  61.                 writeln;
  62.                 writeln (lines:6:0,'     Lines  ');
  63.                 halt;
  64.                 end;
  65.  
  66.              if (ch=cr) or (ch=tab) or (ch=blank) then inword :=
  67.                   false
  68.              else if (ch=newline) then begin
  69.                  inword := false;
  70.                  lines := lines+1;
  71.                  end
  72.              else if not inword then begin
  73.                 inword := true;
  74.                 words := words+1;
  75.                 end;
  76.              end;
  77.           until eof(infile);
  78.        end.
  79.